<!--头部公共部分-->
{include file="common/header" /}
<div style="padding:15px;">
	<form class="layui-form layui-form-pane">
		<div class="layui-form-item">
			<label class="layui-form-label"><span style="color: red;">*</span>配置标识</label>
			<div class="layui-input-block">
				<input type="text" name="name" value="{$systemConfig.name}" required lay-verify="required" placeholder="请输入配置标识" autocomplete="off" class="layui-input">
			</div>
			<div class="layui-form-mid layui-word-aux">用于C函数调用，只能使用英文且不能重复</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"><span style="color: red;">*</span>配置标题</label>
			<div class="layui-input-block">
				<input type="text" name="title" value="{$systemConfig.title}" required lay-verify="required" placeholder="请输入配置标题" autocomplete="off" class="layui-input">
			</div>
			<div class="layui-form-mid layui-word-aux">用于后台显示的配置标题</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"><span style="color: red;">*</span>排序</label>
			<div class="layui-input-block">
				<input type="text" name="sort" value="{$systemConfig.sort}" required lay-verify="required" placeholder="请输入排序" autocomplete="off" class="layui-input">
			</div>
			<div class="layui-form-mid layui-word-aux">用于分组显示的顺序</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"><span style="color: red;">*</span>配置类型</label>
			<div class="layui-input-block">
				<select name="type" lay-verify="required">
					{volist name="config_type_list" id="v"}
					<option value="{$v.id}" {if $systemConfig.type == $v.id}selected{/if}>{$v.name}</option>
					{/volist}
				</select>
			</div>
			<div class="layui-form-mid layui-word-aux">系统会根据不同类型解析配置值</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"><span style="color: red;">*</span>配置分组</label>
			<div class="layui-input-block">
				<select name="group" lay-verify="required">
					<option value="0" {if $systemConfig.group == 0}selected{/if}>不分组</option>
					<option value="1" {if $systemConfig.group == 1}selected{/if}>系统</option>
				</select>
			</div>
			<div class="layui-form-mid layui-word-aux">用于批量设置 不分组则不会显示在系统设置中</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"><span style="color: red;">*</span>配置值</label>
			<div class="layui-input-block">
					<input type="text" name="value" value="{$systemConfig.value}" required lay-verify="required" placeholder="请输入配置值" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item layui-form-text">
			<label class="layui-form-label">说明</label>
			<div class="layui-input-block">
				<textarea name="remark" placeholder="请输入说明" class="layui-textarea">{$systemConfig.remark}</textarea>
			</div>
			<div class="layui-form-mid layui-word-aux">配置详细说明</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<input type="hidden" name="id" value="{$systemConfig.id}" autocomplete="off" class="layui-input">
				<input class="layui-btn" lay-submit lay-filter="form" value="立即提交" readonly>
			</div>
		</div>
	</form>
</div>
<!--底部公共部分-->
{include file="common/footer" /}

<script>
	layui.use(['element', 'table','jquery','form','layer'], function(){
		let $ = layui.jquery
			,element = layui.element
			,layer = layui.layer
			,form = layui.form;

		//监听提交
		form.on('submit(form)', function (data) {
			let field = data.field;
			field.type = $('select[name=type]').val();
			field.group = $('select[name=group]').val();
			let isLoad;
			$.ajax({
				url: '{:url("System/edit_config")}',
				method: "post",
				data: field,
				beforeSend: function () {
					isLoad = layer.load(0, {
						shade: false
					}); //0代表加载的风格，支持0-2
				},
				success: function (result) {
					layer.msg(result.msg);
					if (result.code === 1) {
						setTimeout(function () {
							var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
							parent.layer.close(index); //再执行关闭
							parent.location.reload();
						}, 2000);
					}
				},
				complete: function () {
					layer.close(isLoad)
				},
				error: function (error) {
					console.log(error)
				}
			});
			return false;
		});
	});

</script>